# build library
SET(COM_SRC v4l_capture.c rtp_pack.c network.c timestamp.c)
IF (PLAT STREQUAL "RPI")        ## raspberry pi
  SET (CK_SRC soft_convert.c omx_encode.c ${COM_SRC})
  INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/third-party/ilclient)   # ilclient headers
  AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/third-party/ilclient/ ILCLIENT_SRC) # include ilclient sources
  SET (CK_SRC ${CK_SRC} ${ILCLIENT_SRC})
ELSEIF (PLAT STREQUAL "FSL")        ## freescale
  SET(CK_SRC ipu_convert.c vpu_encode.c ${COM_SRC})
ELSEIF (PLAT STREQUAL "PC")      ## PC
  SET(CK_SRC ffmpeg_convert.c ffmpeg_encode.c ${COM_SRC})
ENDIF (PLAT STREQUAL "RPI")

ADD_LIBRARY(${CK_NAME} SHARED ${CK_SRC})
TARGET_LINK_LIBRARIES(${CK_NAME} ${LIBS})
SET_TARGET_PROPERTIES(${CK_NAME} PROPERTIES
	CLEAN_DIRECT_OUTPUT 1
	VERSION ${CK_MAJOR}.${CK_MINOR} SOVERSION ${CK_MAJOR}
	)
IF (PLAT STREQUAL "RPI")    # additional macros
    SET_TARGET_PROPERTIES(${CK_NAME} PROPERTIES
    COMPILE_FLAGS "-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM "
    )
ENDIF ()

# build cktool
SET(CK_TOOL_SRC cktool.c)
SET(CK_TOOL_NAME cktool)
ADD_EXECUTABLE(${CK_TOOL_NAME} ${CK_TOOL_SRC})
TARGET_LINK_LIBRARIES(${CK_TOOL_NAME} ${CK_NAME})

# build simple_demo
SET(CK_SIMPLE_SRC simple_demo.c)
SET(CK_SIMPLE_NAME simple_demo)
ADD_EXECUTABLE(${CK_SIMPLE_NAME} ${CK_SIMPLE_SRC})
TARGET_LINK_LIBRARIES(${CK_SIMPLE_NAME} ${CK_NAME})

# install header files
INSTALL(FILES ${CK_IDX_HDR} DESTINATION include)
INSTALL(FILES ${CK_HDRS} DESTINATION include/camkit)

# install library
INSTALL(TARGETS ${CK_NAME} LIBRARY DESTINATION lib)

# install cktool
INSTALL(TARGETS ${CK_TOOL_NAME} RUNTIME DESTINATION bin)

# package
INCLUDE(InstallRequiredSystemLibraries)

SET(CPACK_PACKAGE_NAME "Camkit")
SET(CPACK_PACKAGE_VENDOR "Andy")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CAMKIT - CAmera toolKIT")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING.LGPLv3")
SET(CPACK_PACKAGE_VERSION ${CK_VERSION})
SET(CPACK_PACKAGE_VERSION_MAJOR ${CK_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${CK_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${CK_BUILD})
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "Camkit")
IF (WIN32 AND NOT UNIX)
	SET(CPACK_NSIS_DISPLAY_NAME "Camkit")
	SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\git.oschina.net/andyspider/Camkit")
	SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\git.oschina.net/andyspider/Camkit")
	SET(CPACK_NSIS_MODIFY_PATH ON)
ELSE (WIN32 AND NOT UNIX)
	SET(CPACK_SOURCE_STRIP_FILES "")
ENDIF (WIN32 AND NOT UNIX)
SET(CPACK_PACKAGE_EXECUTABLES ${CK_TOOL_NAME} "cktool")
INCLUDE(CPack)
